package com.by.facade.enums.clue;

import com.by.facade.dto.clue.ClueWorkbenchConditionConvertAfterWDTO;
import com.by.toolkit.enums.FlagEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 到课状态
 *
 * @author Tian Wei
 * @version 1.0
 * @date 2024/7/11 10:57
 */
@Getter
@AllArgsConstructor
public enum AttachCourseConvertStatusEnum {

    NO_ATTACH(1, "未到课", item -> {
        item.setUserAttachStatus(FlagEnum.NO.getCode());
        item.setUserCompleteStatus(FlagEnum.NO.getCode());
    }, String.join("=", FlagEnum.NO.getCode().toString(), FlagEnum.NO.getCode().toString())),

    ALREADY_ATTACH(2, "已到课", item ->
    {
        item.setUserAttachStatus(FlagEnum.YES.getCode());
    }, null),

    ALREADY_ATTACH_NO_COMPLETE(3, "已到课未完课", item ->
    {
        item.setUserAttachStatus(FlagEnum.YES.getCode());
        item.setUserCompleteStatus(FlagEnum.NO.getCode());
    }, String.join("=", FlagEnum.YES.getCode().toString(), FlagEnum.NO.getCode().toString())),

    COMPLETE(4, "已经完课", item ->
    {
        item.setUserCompleteStatus(FlagEnum.YES.getCode());
    }, String.join("=", FlagEnum.YES.getCode().toString(), FlagEnum.YES.getCode().toString())),
    ;

    private final Integer status;

    private final String desc;

    private final Consumer<ClueWorkbenchConditionConvertAfterWDTO> consumer;

    private final String uk;

    private final static Map<Integer, AttachCourseConvertStatusEnum> MAP;

    private final static Map<String, Integer> UK_MAP;

    static {
        MAP = Stream.of(AttachCourseConvertStatusEnum.values()).collect(Collectors.toMap(AttachCourseConvertStatusEnum::getStatus, Function.identity()));
        UK_MAP = Stream.of(AttachCourseConvertStatusEnum.values()).filter(item -> item.getUk() != null && !"".equals(item.getUk())).collect(Collectors.toMap(AttachCourseConvertStatusEnum::getUk, AttachCourseConvertStatusEnum::getStatus));
    }

    public static AttachCourseConvertStatusEnum resolveByType(Integer type) {
        return MAP.get(type);
    }

    public static Integer resolveByUk(String uk) {
        return UK_MAP.get(uk);
    }
}
